using UnityEngine;
using System.Collections;
using System.Threading;
public class PositionLocator : MonoBehaviour 
{		
	public int reportTimer = 10;
	public int writeTimer = 5000;
	bool run = true;
	Logging meep;
	Thread t;
	// Use this for initialization
	void Start () 
	{	
		StartCoroutine("Run");
		meep = new Logging();
		t = new Thread(new ThreadStart(meep.Write));
        t.Start();
		meep.writeTimer = writeTimer;
	}
	
	// Update is called once per frame
	void Update () 
	{	
		
	}
	
	void OnCollisionEnter(Collision collision)
	{
		Logging.Tracker.Enqueue(transform.position.x);
		Logging.Tracker.Enqueue(transform.position.y);
		Logging.Tracker.Enqueue(transform.position.z);
			
		Logging.Tracker.Enqueue(transform.rotation.x);
		Logging.Tracker.Enqueue(transform.rotation.y);
		Logging.Tracker.Enqueue(transform.rotation.z);
			
		Logging.Tracker.Enqueue(transform.lossyScale.x);
		Logging.Tracker.Enqueue(transform.lossyScale.y);
		Logging.Tracker.Enqueue(transform.lossyScale.z);
		
		Logging.Tracker.Enqueue(00000000000000000000); //to divide the writes
		
		Debug.Log("Hit");
	}
	
	public void OnDestroy()
    {
		run = false;
		t.Abort();
    }
	
	public IEnumerator Run()
    {
        while (run)
        {
            for(int i = 0; i < reportTimer; i++)
			{
				yield return null;
			}
            Logging.Tracker.Enqueue(transform.position.x);
			Logging.Tracker.Enqueue(transform.position.y);
			Logging.Tracker.Enqueue(transform.position.z);
			
			Logging.Tracker.Enqueue(transform.rotation.x);
			Logging.Tracker.Enqueue(transform.rotation.y);
			Logging.Tracker.Enqueue(transform.rotation.z);
			
			Logging.Tracker.Enqueue(transform.lossyScale.x);
			Logging.Tracker.Enqueue(transform.lossyScale.y);
			Logging.Tracker.Enqueue(transform.lossyScale.z);
			
			Logging.Tracker.Enqueue(00000000000000000000); //to divide the writes
			
            Debug.Log("stored value");
        }
    }
}
